package com.jielihaofeng.chat.controller;


import com.jielihaofeng.chat.query.ChatMessageQuery;
import com.jielihaofeng.chat.query.SearchUserAndGroupQuery;
import com.jielihaofeng.chat.service.impl.ChatService;
import com.jielihaofeng.chat.vo.*;
import com.jielihaofeng.framework.common.page.PageResult;
import com.jielihaofeng.framework.common.utils.Result;
import com.jielihaofeng.system.vo.SysUserVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天接口
 */
@RestController
@RequestMapping("chat/test")
@Tag(name = "聊天")
@AllArgsConstructor
public class ChatTestController {

    private ChatService chatService;

    @RequestMapping("/")
    public String chat() {
        return "chat";
    }

    @GetMapping("/getFeedList")
    public Result<List<FeedListItemVO>> getFeedList(Long userId) {
        List<FeedListItemVO> feedList = chatService.getFeedList(userId);
        return Result.ok(feedList);
    }

    @GetMapping("/getMessageList")
    public Result<PageResult<ChatMessageVO>> getMessageList(ChatMessageQuery query) {
        PageResult<ChatMessageVO> messageList = chatService.getMessageList(query);
        return Result.ok(messageList);
    }

    @GetMapping("/getFriendAndGroupList")
    public Result<FriendAndGroupVO> getFriendAndGroupList(Long userId) {
        FriendAndGroupVO friendAndGroupList = chatService.getFriendAndGroupList(userId);
        return Result.ok(friendAndGroupList);
    }

    /**
     * 搜索朋友和群组
     *
     * @param query 查询条件
     * @return 搜索结果
     */
    @GetMapping("/searchUserAndGroup")
    public Result<SearchUserAndGroupVO> searchUserAndGroup(SearchUserAndGroupQuery query) {
        SearchUserAndGroupVO searchUser = chatService.searchUserAndGroup(query);
        return Result.ok(searchUser);
    }

    @GetMapping("/searchUserList")
    public Result<List<FriendAndGroupItemVO>> searchUserList(SearchUserAndGroupQuery query) {
        List<FriendAndGroupItemVO> result = chatService.searchUserList(query);
        return Result.ok(result);
    }

    @GetMapping("/searchGroupList")
    public Result<List<FriendAndGroupItemVO>> searchGroupList(SearchUserAndGroupQuery query) {
        List<FriendAndGroupItemVO> result = chatService.searchGroupList(query);
        return Result.ok(result);
    }

    @PostMapping("/addFriend")
    public Result<Boolean> addFriend(@RequestBody ChatUserRelationVO chatUserRelationVO) {
        boolean result = chatService.addFriend(chatUserRelationVO);
        return Result.ok(result);
    }

    @PostMapping("/joinGroup")
    public Result<Boolean> joinGroup(@RequestBody ChatGroupUserVO chatGroupUserVO) {
        boolean result = chatService.joinGroup(chatGroupUserVO);
        return Result.ok(result);
    }

    @GetMapping("/getRequestFriendList")
    public Result<List<FriendAndGroupItemVO>> getRequestFriendList(Long userId) {
        List<FriendAndGroupItemVO> friendList = chatService.getRequestFriendList(userId);
        return Result.ok(friendList);
    }

    @GetMapping("/receiveFriendRequest")
    public Result<Boolean> receiveFriendRequest(Long userId, Long friendId) {
        boolean result = chatService.receiveFriendRequest(userId, friendId);
        return Result.ok(result);
    }

    @GetMapping("/rejectFriendRequest")
    public Result<Boolean> rejectFriendRequest(Long userId, Long friendId) {
        boolean result = chatService.rejectFriendRequest(userId, friendId);
        return Result.ok(result);
    }

    @PostMapping("/register")
    public Result register(@RequestBody SysUserVO sysUserVO) {
        return chatService.register(sysUserVO);
    }
}